#include "System_Init.h"
#include "fsl_port.h"

static void init_leds(void)
{
    /* Define the init structure for the output LED pin*/
    gpio_pin_config_t led_config = {
        kGPIO_DigitalOutput, 1,
    };
    
    GPIO_PinInit(BOARD_INITPINS_LED_RED_GPIO, BOARD_INITPINS_LED_RED_PIN, &led_config);
    GPIO_PinInit(BOARD_INITPINS_LED_BLUE_GPIO, BOARD_INITPINS_LED_BLUE_PIN, &led_config);
    GPIO_PinInit(BOARD_INITPINS_LED_GREEN_GPIO, BOARD_INITPINS_LED_GREEN_PIN, &led_config);
    
    return;
}

static void init_keys(void)
{
    /* Define the init structure for the output LED pin*/
    gpio_pin_config_t key_config = {
        kGPIO_DigitalInput, 0,
    };
    
    PORT_SetPinInterruptConfig(BOARD_INITPINS_BUTTON1_PORT, BOARD_INITPINS_BUTTON1_PIN, kPORT_InterruptFallingEdge);
    EnableIRQ(BUTTON1_IRQ);
    GPIO_PinInit(BOARD_INITPINS_BUTTON1_GPIO, BOARD_INITPINS_BUTTON1_PIN, &key_config);
    
    PORT_SetPinInterruptConfig(BOARD_INITPINS_BUTTON2_PORT, BOARD_INITPINS_BUTTON2_PIN, kPORT_InterruptFallingEdge);
    EnableIRQ(BUTTON2_IRQ);    
    GPIO_PinInit(BOARD_INITPINS_BUTTON2_GPIO, BOARD_INITPINS_BUTTON2_PIN, &key_config);
    
    return;
}

void init_system(void)
{
    init_leds();
    init_keys();
    return;
}